package com.kjj.gift.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.kjj.gift.clients.SmsValidateCodeClient;
import com.kjj.gift.domain.User;
import com.kjj.gift.dto.SMSCodeDto;
import com.kjj.gift.exception.asserts.Assert;
import com.kjj.gift.exception.code.StatusCode;
import com.kjj.gift.mapper.UserMapper;
import com.kjj.gift.service.ISmsCodeService;
import com.kjj.gift.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SmsCodeServiceImpl implements ISmsCodeService {

    @Autowired
    private UserMapper userMapper;
    @Autowired
    private SmsValidateCodeClient smsValidateCodeClient;
    @Override
    public AjaxResult sendSmsRegisterCode(SMSCodeDto smsCodeDto) {
        String phone = smsCodeDto.getPhone();
        Assert.assertNotEmpty(phone, StatusCode.CODE_400);
        List<User> users = userMapper.selectList(new EntityWrapper<User>().eq("phone", phone));
        Assert.assertListIsEmpty(users,StatusCode.CODE_400_USER_EXSIT);
        //远程调用发送验证码
        return smsValidateCodeClient.sendSmsCode(smsCodeDto);
    }
}
